package org.projectname.entity.book;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.Min;
import javax.validation.constraints.Size;

import org.hibernate.validator.constraints.NotBlank;
import org.hibernate.validator.constraints.Range;
import org.hibernate.validator.constraints.URL;
import org.joda.time.DateTime;
import org.springframework.format.annotation.DateTimeFormat;

/**
 * 图书实体
 * @author Panda
 *
 */
@Entity
@Table(name = "t_book")
public class Book {
//	public static void main(String[] args) {
//		Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
//		Book book = new Book();
//		book.setStores(-123);
//
//		Set<ConstraintViolation<Book>> constraintViolations = validator.validate(book);
//		for (ConstraintViolation<Book> constraintViolation : constraintViolations) {
//			System.out.println(constraintViolation.getMessage());
//		}
//	}
	
	/** 主键 自增 */
	@Id
	@GeneratedValue (strategy = GenerationType.IDENTITY)	
	private Integer id;
	
	/** 所属类别Id */
	@Column (name = "book_part_id")
	private int bookPartId;

	/** 书名 */
	@Column (name = "book_name")
	@NotBlank
	private String bookName;
	
	/** 介绍 */
	@Size(min = 10, max = 200)
	private String intro;
	
	/** 出版日期 */
	@Column (name = "publication_date")
	@DateTimeFormat(pattern = "yyyy-MM-dd")
	private Date publicationDate;
	
	/** 
	 * 出版社网址 */
	@Transient
	@Column (name = "publishing_house_url")
	@URL
	private String publishingHouseUrl;
	
	/** 封面 */
	@Transient
	@Column (name = "front_cover")
	private String frontCover;

	/** 价格 */
	@Transient
	@Min(0)
	private BigDecimal price;
	
	/** 库存 */
	@Transient
	@Range(min = 0, max = 1000)	
	private Integer stores;
	
	/** 数据添加时间 */
	@Transient
	@Column (name = "insert_time", updatable = false)
	private Date insertDate = new Date();
	
	/** 数据更新时间 */
	@Transient
	@Column (name = "update_time", insertable = false)
	private Date updateDate = new Date();
	
	/** 所属类别（不进行数据库映射） */
	@Transient
	private BookPart bookPart;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;		
	}

	public String getIntro() {
		return intro;
	}

	public void setIntro(String intro) {
		this.intro = intro;
	}

	public Date getPublicationDate() {
		return publicationDate;
	}

	public void setPublicationDate(Date publicationDate) {
		this.publicationDate = publicationDate;
	}

	public BigDecimal getPrice() {
		return price;
	}

	public void setPrice(BigDecimal price) {
		this.price = price;
	}

	public Integer getStores() {
		return stores;
	}

	public void setStores(Integer stores) {
		this.stores = stores;
	}

	public Date getInsertDate() {
		return insertDate;
	}

	public void setInsertDate(Date insertDate) {
		this.insertDate = insertDate;
	}

	public Date getUpdateDate() {
		return updateDate;
	}

	public void setUpdateDate(Date updateDate) {
		this.updateDate = updateDate;
	}

	public int getBookPartId() {
		return bookPartId;
	}

	public void setBookPartId(int bookPartId) {
		this.bookPartId = bookPartId;
	}

	public BookPart getBookPart() {
		return bookPart;
	}

	public void setBookPart(BookPart bookPart) {
		this.bookPart = bookPart;
	}

	public String getBookName() {
		return bookName;
	}

	public void setBookName(String bookName) {
		this.bookName = bookName;
	}

	public String getPublishingHouseUrl() {
		return publishingHouseUrl;
	}

	public void setPublishingHouseUrl(String publishingHouseUrl) {
		this.publishingHouseUrl = publishingHouseUrl;
	}

	public String getFrontCover() {
		return frontCover;
	}

	public void setFrontCover(String frontCover) {
		this.frontCover = frontCover;
	}
}
